package com.jxd.dianping.recommend;

import com.jxd.dianping.dao.RecommendDOMapper;
import com.jxd.dianping.model.RecommendDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Service
public class RecommendService implements Serializable {
    @Autowired
    private RecommendDOMapper recommendDOMapper;

    // 召回数据 根据userId获取shopIds
    public List<Integer> recall(Integer userId) {
        RecommendDO recommendDO = recommendDOMapper.selectByPrimaryKey(userId);
        String recommend = recommendDO.getRecommend();
        // 设置默认推荐
        if (recommendDO == null) {
            recommendDO = recommendDOMapper.selectByPrimaryKey(999999999);
        }
        String[] shopIdStr = recommendDO.getRecommend().split(",");
        List<Integer> shopIds = new ArrayList<>();
        for (int i = 0; i < shopIdStr.length; i++) {
            shopIds.add(Integer.parseInt(shopIdStr[i]));
        }
        return shopIds;
    }

}
